﻿using NUnit.Framework;
using Validate.Extensions;

namespace Validate.UnitTests
{
    [TestFixture]
    public class ValidatorTests_RegexMatches
    {
        [Test]
        public void ShouldPassForMatchesRegex()
        {
            var person = new Person {Name = "Some Person"};
            var validator = person.Validate().MatchesRegex(p => p.Name, "Some\\sPerson",message: "Regex match failed.");
            Assert.IsTrue(validator.IsValid);
        }

        [Test]
        public void ShouldFailForMatchesRegex()
        {
            var person = new Person { Name = "Some Person" };
            var validator = person.Validate().MatchesRegex(p => p.Name, "Some\\sOther\\sPerson", message: "Regex match failed.");
            Assert.IsFalse(validator.IsValid);
        }

        [Test]
        public void ShouldBeAbleToVerifyAutoGeneratedValidationMessage1()
        {
            var person = new Person { HomeAddress = new Address{City = "Wrong City", Zipcode = "Wrong Zipcode"}};
            var validator = person.Validate(new ValidationOptions { StopOnFirstError = false })
                .MatchesRegex(v => v.HomeAddress.City, @"London\s\(South\)")
                .MatchesRegex(v => v.HomeAddress.Zipcode, @"\d{5,6}");
            Assert.That(validator.Errors[0].Message, Is.EqualTo(@"Address.City should match pattern ""London\s\(South\)""."));
            Assert.That(validator.Errors[1].Message, Is.EqualTo(@"Address.Zipcode should match pattern ""\d{5,6}""."));
        }
    }
}